////
//// Source code recreated from a .class file by IntelliJ IDEA
//// (powered by Fernflower decompiler)
////
//
//package com.navinfo.opentsp.platform.computing.serializer;
//
//import com.alibaba.fastjson.JSON;
//import com.google.common.base.Charsets;
//import com.google.common.collect.Lists;
//import com.googlecode.protobuf.format.JsonFormat;
//import com.navinfo.opentsp.platform.computing.dto.*;
//import com.navinfo.opentsp.platform.computing.util.DateUtils;
//import com.navinfo.stream.qingqi.protocol.java.LCLocationData;
//import com.navinfo.stream.qingqi.protocol.java.LCVehicleBreakdown;
//import com.navinfo.stream.qingqi.protocol.java.LCVehicleStatusData;
//import org.apache.flume.Context;
//import org.apache.flume.Event;
//import org.apache.flume.serialization.EventSerializer;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//
//import java.io.IOException;
//import java.io.OutputStream;
//import java.util.List;
//
///**
// * 0200位置信息
// * HDFS_Sink的LocationData序列化器，拼接成字段间通过\001分割的字符串
// */
//public class HDFSLocationDataSerializerNew implements EventSerializer {
//    private static final Logger logger = LoggerFactory.getLogger(HDFSLocationDataSerializerNew.class);
//
//    private final String APPEND_NEWLINE = "appendNewline";
//    private final boolean appendNewline;
//    private final String splitStr = "\001";
//    private final OutputStream out;
//
//    private HDFSLocationDataSerializerNew(OutputStream out, Context ctx) {
//        this.appendNewline = ctx.getBoolean(APPEND_NEWLINE, true);
//        this.out = out;
//    }
//
//    public boolean supportsReopen() {
//        return false;
//    }
//
//    public void afterCreate() {}
//
//    public void afterReopen() {}
//
//    public void beforeClose() {}
//
//    public void flush() throws IOException {
//        this.out.flush();
//    }
//
//    public void write(Event event) throws IOException {
//        try {
//            LCLocationData.LocationData locationData = LCLocationData.LocationData.parseFrom(event.getBody());
//            LCLocationData.LocationData data = locationData.toBuilder()
//                    .setPartTime(DateUtils.format(locationData.getGpsDate() * 1000, "yyyyMMdd"))
//                    .setHashtid((int)locationData.getTerminalId()%32)
//                    .build();
//            String dataJson = JsonFormat.printToString(data);
//            //将0200报文拼接后写入hdfs
//            this.out.write(dataJson.getBytes(Charsets.UTF_8));
//            if (this.appendNewline) {
//                this.out.write(10);
//            }
//        }catch (Exception e){
//            logger.error("执行HDFS的LocationData拦截器失败：" + e.getMessage(), e);
//        }
//    }
//
//    public static List<String> getTemAlarmDtos(List<LCLocationData.TemAddition> temAlarmList){
//        List<String> temAlarmDtos = Lists.newArrayList();
//        if(temAlarmList == null){
//            return temAlarmDtos;
//        }
//        for(LCLocationData.TemAddition temAddition : temAlarmList){
//            temAlarmDtos.add(TemAlarmDto.parseString(temAddition));
//        }
//        return temAlarmDtos;
//    }
//
//    public static List<String> getKeyPointFences(List<LCLocationData.KeyPointFenceAddition> keyPointFenceAdditionList){
//        List<String> defenceAdditionDtos = Lists.newArrayList();
//        if(keyPointFenceAdditionList == null){
//            return defenceAdditionDtos;
//        }
//        for(LCLocationData.KeyPointFenceAddition keyPointFenceAddition : keyPointFenceAdditionList){
//            defenceAdditionDtos.add(DefenceAdditionDto.parseString(keyPointFenceAddition));
//        }
//        return defenceAdditionDtos;
//    }
//
//    public static List<String> getParkingAdditions(List<LCLocationData.OvertimeParkingAddition> overtimeParkingAdditions){
//        List<String> parkingAdditionDtos = Lists.newArrayList();
//        if(overtimeParkingAdditions == null){
//            return parkingAdditionDtos;
//        }
//        for(LCLocationData.OvertimeParkingAddition overtimeParkingAddition : overtimeParkingAdditions){
//            parkingAdditionDtos.add(ParkingAdditionDto.parseString(overtimeParkingAddition));
//        }
//        return parkingAdditionDtos;
//    }
//
//    public static List<String> getModuleVoltagess(List<LCLocationData.ModuleVoltage> moduleVoltages){
//        List<String> moduleVoltagesDtos = Lists.newArrayList();
//        if(moduleVoltages == null){
//            return moduleVoltagesDtos;
//        }
//        for(LCLocationData.ModuleVoltage moduleVoltage : moduleVoltages){
//            moduleVoltagesDtos.add(ModuleVoltagesDto.parseString(moduleVoltage));
//        }
//        return moduleVoltagesDtos;
//    }
//
//    public static List<String> getStaytimeParkingDtos(List<LCLocationData.StaytimeParkingAddition> staytimeParkings){
//        List<String> staytimeParkingDtos = Lists.newArrayList();
//        if(staytimeParkings == null){
//            return staytimeParkingDtos;
//        }
//        for(LCLocationData.StaytimeParkingAddition staytimeParking : staytimeParkings){
//            staytimeParkingDtos.add(StaytimeParkingAdditionDto.parseString(staytimeParking));
//        }
//        return staytimeParkingDtos;
//    }
//
//    public static List<String> getSpeedAdditions(List<LCLocationData.SpeedAddition> speedAdditions){
//        List<String> speedAdditionDtos = Lists.newArrayList();
//        if(speedAdditions == null){
//            return speedAdditionDtos;
//        }
//        for(LCLocationData.SpeedAddition speedAddition : speedAdditions){
//            speedAdditionDtos.add(SpeedAdditionDto.parseString(speedAddition));
//        }
//        return speedAdditionDtos;
//    }
//
//    public static List<String> getAreaAdditions(List<LCLocationData.AreaAddition> areaAdditions){
//        List<String> areaAdditionDtos = Lists.newArrayList();
//        if(areaAdditions == null){
//            return areaAdditionDtos;
//        }
//        for(LCLocationData.AreaAddition areaAddition : areaAdditions){
//            areaAdditionDtos.add(AreaAdditionDto.parseString(areaAddition));
//        }
//        return areaAdditionDtos;
//    }
//
//    public static List<String> getRouteAdditions(List<LCLocationData.RouteAddition> routeAdditions){
//        List<String> routeAdditionDtos = Lists.newArrayList();
//        if(routeAdditions == null){
//            return routeAdditionDtos;
//        }
//        for(LCLocationData.RouteAddition routeAddition : routeAdditions){
//            routeAdditionDtos.add(RouteAdditionDto.parseString(routeAddition));
//        }
//        return routeAdditionDtos;
//    }
//
//    public static List<String> getVehicleBreakdowns(List<LCVehicleBreakdown.VehicleBreakdown> vehicleBreakdowns){
//        List<String> breakdownAdditionDtos = Lists.newArrayList();
//        if(vehicleBreakdowns == null){
//            return breakdownAdditionDtos;
//        }
//        for(LCVehicleBreakdown.VehicleBreakdown vehicleBreakdown : vehicleBreakdowns){
//            String data = BreakdownAdditionDto.parseString(vehicleBreakdown);
//            if(data == null){
//                continue;
//            }
//            breakdownAdditionDtos.add(data);
//        }
//        return breakdownAdditionDtos;
//    }
//
//    public static List<String> getVehicleStatusDataString(List<LCVehicleStatusData.VehicleStatusData> vehicleStatusDatas){
//        List<String> vehicleStatusAdditionDtos = Lists.newArrayList();
//        if(vehicleStatusDatas == null){
//            return vehicleStatusAdditionDtos;
//        }
//        for(LCVehicleStatusData.VehicleStatusData vehicleStatusData : vehicleStatusDatas){
//            vehicleStatusAdditionDtos.add(VehicleStatusAdditionDto.parseString(vehicleStatusData));
//        }
//        return vehicleStatusAdditionDtos;
//    }
//
//
//    public static class Builder implements EventSerializer.Builder {
//        public Builder() { }
//        public EventSerializer build(Context context, OutputStream out) {
//            return  new HDFSLocationDataSerializerNew(out, context);
//        }
//    }
//}
